import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class flieies0�shit here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Fliesband extends Plattform
{
    GreenfootImage image1 = new GreenfootImage("flies1.png");
    GreenfootImage image2 = new GreenfootImage("flies2.png");
    boolean rutschStart = false;
    
    public Fliesband(int h, int b, int m){
        movementspeed = m;
        höhe = h;
        breite = b;
    }

    public void act() 
    {   
        rutschen();
        bewegen();
        getImage().scale(breite,höhe);
        animation();
    }   

    public void animation(){
        long zeit = System.currentTimeMillis()/100;
        if(zeit%2==0){
            setImage(image1);
        } else {
            setImage(image2);
        }
    }

    public void rutschen(){
        
        Actor held_links = getOneIntersectingObject(Held.class);
        
        if(held_links != null && getY()-held_links.getY()>120 && getY()-held_links.getY()<130){
            held_links.setLocation(held_links.getX()+1,held_links.getY());
            //.out.println(held_links.getY() - getY());
        }
    
    }

    public void bewegen(){
        if(movementspeed > 0){
            if(nachRechts == true){
                setLocation(getX()+movementspeed,getY());
                zaehler++;
            } else {
                setLocation(getX()-movementspeed,getY());
                nachRechts = false;
                zaehler--;
            }

            if(zaehler == reichweite){
                nachRechts = false;
            } else if(zaehler == 0){
                nachRechts = true;
            }
        }

    }
}
